
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <style>
        #ii1{
            opacity: 0.5;
        }
        #ii1:hover{
            opacity: 1.0;
        }
        body{
        }
        .el-header a{
            color: #666;
            text-decoration: none;
        }
        .el-menu.el-menu--horizontal{
            border-bottom: 0;
        }
        .el-table .el-table__cell{
            padding: 0;
        }
        .el-table .cell{
            white-space: nowrap;
            text-overflow: ellipsis;
        }
        #d2{
            width: 50px;
            height: 200px;
            background-color: blue;
            position: fixed;
            right: 40px;
            bottom:50% ;
        }
        h3{
            position: absolute;
            right: 40px
        }
    </style>
</head>
<body>
<div id="app">
    <el-container>
        <el-header height="60px" style="width: 100%">
            <div style="background-color: #f09117">
                <el-row>
                    <el-col :span="4"><div class="grid-content bg-purple">
                        <img style="vertical-align: middle;" src="catimg/logo.png" width="150" alt="">
                    </div></el-col>
                    <el-col :span="16"><div class="grid-content bg-purple-light">
                        <el-menu @select="handleSelect" style="width:100%;margin: 0 auto" mode="horizontal" background-color="#f09117"
                                 text-color="#fff" active-text-color="#fff">
                            <el-menu-item v-for="c in categoryArr"
                                          :index="c.id">{{c.name}}</el-menu-item>
                            <div style="float: right;position: relative;top: 10px">
                                <el-input type="text" @keydown.native.enter="search()" v-model="wd">
                                    <!--在文本框中内嵌一个搜索按钮-->
                                    <el-button slot="append" icon="el-icon-search" @click="search()"></el-button>
                                </el-input>
                            </div>
                        </el-menu>
                    </div></el-col>
                    <el-col :span="4"><div class="grid-content bg-purple">
                        <div v-if="isLogin" style="position: relative">
                            <h3>欢迎{{user.nickname}}</h3>
                            <a href="posts.html">猫课堂</a><el-divider direction="vertical"></el-divider>
                            <a style="position: absolute;right: 40px" href="javascript:void(0)" @click="logout()">退出登录</a>
                        </div>
                        <div v-else>
                            <a href="login.html" style="position: absolute;right: 40px">登录</a><el-divider direction="vertical"></el-divider>
                            <a href="reg.html" style="position: absolute;right: 0">注册</a>
                        </div>
                    </div></el-col>
                </el-row>
            </div>
        </el-header>
        <div id="d2">
            <el-button plain>朴素按钮</el-button>
            <el-button style="margin: 0;width: 50px" plain>1</el-button>
            <el-button style="margin: 0" plain>朴素按钮</el-button>
        </div>
        <el-main style="width: 1200px;margin: 0 auto">
            <div style="width: 1000px;margin: 0 auto">
                <el-row gutter="20">
                    <!--走马灯开始-->
                    <el-carousel trigger="click" height="450px">
                        <el-carousel-item v-for="url in bannerArr">
                            <img :src="url" width="100%" alt="">
                        </el-carousel-item>
                    </el-carousel>
                    <!--走马灯结束-->
                </el-row>
            </div>
            <el-row gutter="20">
                <el-col span="6" v-for="p in productArr">
                    <el-card>
                        <a :href="'/detail.html?id='+p.id">
                            <img id="ii1" :src="p.url" width="100%" height="180">
                        </a>
                        <a :href="'/detail.html?id='+p.id">
                            <p style="font-size: 14px;height: 30px">{{p.title}}</p>
                        </a>
                        <p>

                            <b>￥{{p.price}}</b> <s>{{p.oldPrice}}</s>
                            <span style="float: right">销量:{{p.saleCount}}件</span>
                        </p>
                    </el-card>
                </el-col>
            </el-row>
        </el-main>
    </el-container>
</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>

<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                bannerArr:["catimg/bizhi2ud.jpg","catimg/daimao2ud.jpg","catimg/lihua1ud.jpg","catimg/bizhi4ud.jpg"],
                productArr:[],
                categoryArr:[],
                wd:'',
                isLogin:false,
                user:[]
            }
        },
        methods:{
            handleSelect(key,keyPath){
                //key就是分类的id
                location.href="/result.html?id="+key;
            },
            logout() {
                if (confirm("您确定退出？")){
                    axios.get("/logout").then(function (response) {
                        v.isLogin=false;
                    })
                }
            },
            search(){
                location.href="result.html?wd="+v.wd;
            }
        },
        created:function () {
            axios.get("/product/selectIndex").then(function (response) {
                let jsonResult = response.data;
                if (jsonResult.state == 20000) {
                    v.productArr = jsonResult.data;
                }
            });
            //  axios.get("/product/selectIndex").then(function (response) {
            //      v.productArr=response.data;})















            axios.get("/category/select").then(function (response) {
                v.categoryArr=response.data;
            })
            axios.get("/currentUser").then(function (response) {
                v.user=response.data;
                v.isLogin=!response.data=='';
            })
        }
    })
</script>
</html>
